<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<script>
    function checkAll() {
        var boxList = document.getElementsByName("checkbox");
        if (null != boxList) {
            alert("确定全选？")
            for (var i = 0; i < boxList.length; i++) {
                boxList[i].checked = true;
            }
        }
    }

    function cancleAll() {
        var boxList = document.getElementsByName("checkbox");
        if (null != boxList) {
            alert("取消全选？")
            for (var i = 0; i < boxList.length; i++) {
                boxList[i].checked = false;
            }
        }
    }


    function myFunction() {
        carName = "Volvo";
        return carName;
    }

    window.carName = "ceshi";
    alert(carName);

    function myFunction() {
        var inpObj = document.getElementById("id1");
        if (inpObj.checkValidity() == false) {
            document.getElementById("demo").innerHTML = inpObj.validationMessage;
        }
    }
</script>
<body>
看书：<input type="checkbox" name="checkbox" value=1><br>
写字：<input type="checkbox" name="checkbox" value=2><br>
打飞机：<input type="checkbox" name="checkbox" value=3><br>
玩游戏：<input type="checkbox" name="checkbox" value=4><br>
<button onclick="checkAll()">全选</button>
<button onclick="cancleAll()">取消全选</button>
<button onclick="getElementById('demo').innerHTML=Date()">现在的时间是?</button>
<p id="demo"></p>
</body>
</html>